package Code;

public class Point 
{
	private double x;
	private double y;
	
	/**********************************
	 * Constructor to create a Point
	 * @param x	the x-value of the pt
	 * @param y the y-value of the pt
	 ***********************************/
	public Point(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	public Point(String pair) {
		String[] pairs = pair.split(",");
		this.x = Double.parseDouble(pairs[0]);
		this.y = Double.parseDouble(pairs[1]);
	}
	
	/***********************************
	 * @return x-value of the pt
	 ************************************/
	public double getX()
	{
		return x;
	}
	
	/***********************************
	 * @return y-value of the pt
	 ***********************************/
	public double getY()
	{
		return y;
	}
	
	/***************************************
	 * Calcuates the distance between 2 pts
	 * @param other the other pt
	 * @return the distance 
	 **************************************/
	public double calcDistance(Point other)
	{
		return Math.sqrt(Math.pow(x-other.x, 2)+Math.pow(y-other.y, 2));
	}
	
	/**************************************
	 * Calculates the slope between 2 pts
	 * @param other the other pt
	 * @return the slope
	 *************************************/
	public double calcSlope(Point other)
	{
		if (x == other.x)
			return Double.POSITIVE_INFINITY;
		return (y-other.y)/(x-other.x);
	}
	
	/*************************************
	 * Calculates the y-intercept for the
	 * line between 2 pts
	 * @param other the other pt
	 * @return the y-ints
	 *************************************/
	public double calcYInt(Point other)
	{
		double slope = calcSlope(other);
		if (slope == Double.POSITIVE_INFINITY)
		{
			if (x == 0)
				return 0;
			else
				return Double.POSITIVE_INFINITY;
		}
		return y - slope * x;
	}

	/*************************************
	 * Calculates the y-intercept for the
	 *    given the curr Pt and a slope
	 * @param m the slope
	 * @return the y-ints
	 * NOTE: assumes m != infinity
	 *************************************/
	public double calcYInt(double m) 
	{
		return y - m*x;
	}
	
	public String toString() {
		return String.format(" (%.2f, %.2f) ", x, y);
	}
	
	public static Point ZERO = new Point(0,0);
	
	public boolean equals(Point pt)
	{
		if (pt.getX() != x)
			return false;
		if (pt.getY() != y)
			return false;
		return true;
	}
}
